
#define _CRT_SECURE_NO_WARNINGS 1
#include"Date.h"
bool Date::operator==(const Date& y)
{
	return _year == y._year
		&& _month == y._month
		&& _day == y._day;
}
bool Date::operator<(const Date& y)
{
	if (_year < y._year)
	{
		return true;
	}
	else if (_year == y._year)
	{
		if (_month < y._month)
		{
			return true;
		}
		else if (_month == y._month)
		{
			return _day < y._day;
		}
	}
	return false;
}

Date& Date::operator=(const Date& y)
{
	_year = y._year;
	_month = y._month;
	_day = y._day;
	return *this;
}

bool Date::operator<=(const Date& y)
{
	return *this < y && *this == y;
}

bool Date::operator>(const Date& y)
{
	return !(*this <= y);
}

bool Date::operator>=(const Date& y)
{
	return !(*this < y);
}

Date& Date::operator+=(int day)
{
	_day += day;
	if (_day > Getmonthday(_year, _month))
	{
		_day -= Getmonthday(_year, _month);
		_month++;
		if (_month > 12)
		{
			_month -= 12;
			_year++;
		}
	}
	return *this;
}

Date Date::operator+(int day)
{
	Date temp = *this;
	temp += day;
	return temp;
}

Date& Date::operator-=(int day)
{
	_day -= day;
	while (_day<=0)
	{
		_month--;
		if (_month <= 0)
		{
			_year--;
			_month += 12;
		}
		_day += Getmonthday(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day)
{
	Date temp = *this;
	temp -= day;
	return temp;
}


Date& Date::operator++()
{
	_day += 1;
	return *this;
}
Date Date::operator++(int)
{
	Date temp = *this;
	*this += 1;
	return temp;
}

Date& Date::operator--()
{
	_day -= 1;
	return *this;
}
Date Date::operator--(int)
{
	Date temp = *this;
	*this -= 1;
	return temp;
}
bool Date::operator!=(const Date& d)
{
	return !(*this == d);
}

int Date::operator-(const Date& y)
{
	int flag = 1;
	Date max = *this;
	Date min = y;
	if (*this < y)
	{
		flag = -1;
		max = y;
		min = *this;
	}
	int n = 0;
	while (min!=max)
	{
		++min;
		++n;
	}
	return n*flag;
}
